package com.dfbz.service;

import com.dfbz.dao.ArticleDao;
import com.dfbz.entity.Article;
import com.dfbz.entity.User;
import com.dfbz.utils.PageUtils;

import java.util.List;
import java.util.Map;

public class ArticleService {
    private ArticleDao articleDao = new ArticleDao();

    /**
     * 分页/模糊查询所有文章列表及
     * @param cureePage
     * @param title
     * @return
     */
    public PageUtils<Map<String ,Object>> findArticleList(Integer cureePage, String title) {
        return articleDao.findArticleList(cureePage,title);
    }

    /**
     * 根据id查询文章
     * @param id
     * @return
     */
    public Article findArticleById(Long id) {
        return articleDao.findArticleById(id);
    }

    /**
     * 根据文章id查询被关注数
     * @param aid
     * @return
     */
    public Long findCollectCountById(long aid) {
        return articleDao.findCollectCountById(aid);
    }

    /**
     * 更新文章浏览数
     * @param aid
     */
    public void updateBrowseCountById(long aid) {
        articleDao.updateBrowseCountById(aid);
    }

    /**
     * 查询关注该文章的用户信息
     * @param aid
     * @param uid
     * @return
     */
    public List<User> findUsersByaid(long aid,long uid) {
        return articleDao.findUsersByaid(aid,uid);
    }

    /**
     * 查询我是否关注该文章
     * @param uid
     * @param aid
     * @return
     */
    public Integer IsAttentionWithMe(Long uid, long aid) {
        return articleDao.IsAttentionWithMe(uid,aid);
    }

    /**
     * 文章取关
     * @param uid
     * @param aid
     */
    public void removeCollectArticle(Long uid, long aid) {
        articleDao.removeCollectArticle(uid,aid);
    }

    /**
     * 文章加关注
     * @param uid
     * @param aid
     */
    public void collectArticle(Long uid, long aid) {
        articleDao.collectArticle(uid,aid);
    }

    /**
     * 分页/模糊查询我关注的文章列表
     * @param uid
     * @param cureePage
     * @param title
     * @return
     */
    public PageUtils<Map<String,Object>> findMyCollectById(Long uid, Integer cureePage, String title) {
        return articleDao.findMyCollectById(uid,cureePage,title);

    }

    /**
     * 发布文章
     * @param article
     */
    public void addArticle(Article article) {
        articleDao.addArticle(article);
    }
}
